package com.carlife.provider;

public class ConditionItem {
	
	public static final int EQ = 0;
	public static final int NEQ = 1;
	public static final int GE = 2;
	public static final int GT = 3;
	public static final int LE = 4;
	public static final int LT = 5;	
	public static final int LIKE = 6;
	
	
	private String key = null;
	private Object value = null;
	private int compareSymbol = 0;
	
	
	public ConditionItem(String key, Object value, int compareSymbol) {
		super();
		this.key = key;
		this.value = value;
		this.compareSymbol = compareSymbol;
	}


	public String getKey() {
		return key;
	}


	public Object getValue() {
		return value;
	}


	public int getCompareSymbol() {
		return compareSymbol;
	}
	
	public String getPrepareSql() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(key).append(" ");
		switch (this.compareSymbol) {
		case EQ:
			buffer.append("=");
			break;
		case NEQ:
			buffer.append("!=");
			break;
		case GE:
			buffer.append(">=");
			break;
		case GT:
			buffer.append(">");
			break;
		case LE:
			buffer.append("<=");
			break;
		case LT:
			buffer.append("<");
			break;
		case LIKE:
			buffer.append("like");
			break;
		default:
			break;
		}
		buffer.append("?");
		return buffer.toString();
	}
	
	public String getFullSql() {
		StringBuffer buffer = new StringBuffer();
		buffer.append(key).append(" ");
		switch (this.compareSymbol) {
		case EQ:
			buffer.append("=");
			break;
		case NEQ:
			buffer.append("!=");
			break;
		case GE:
			buffer.append(">=");
			break;
		case GT:
			buffer.append(">");
			break;
		case LE:
			buffer.append("<=");
			break;
		case LT:
			buffer.append("<");
			break;
		case LIKE:
			buffer.append("like");
			break;
		default:
			break;
		}
		buffer.append(value.toString());
		return buffer.toString();
	}

}
